package org.wu.framework.lazy.database.datasource.proxy;

import org.wu.framework.lazy.database.datasource.proxy.connection.LazyProxyConnection;
import org.wu.framework.lazy.database.datasource.proxy.handler.JdbcHandlerAdapter;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 *
 *
 */
public interface LazyProxyDataSource extends LazyDataSource {


    static LazyProxyDataSource instance(DataSource targetDataSource) {
        return LazyProxyDataSourceInvocationHandler.createProxy(targetDataSource, new JdbcHandlerAdapter());
    }

    static LazyProxyDataSource instance(DataSource targetDataSource, JdbcHandlerAdapter jdbcHandlerAdapter) {
        return LazyProxyDataSourceInvocationHandler.createProxy(targetDataSource, jdbcHandlerAdapter);
    }


    /**
     * <p>Attempts to establish a connection with the data source that
     * this {@code DataSource} object represents.
     *
     * @return  a connection to the data source
     * @throws SQLException if a database access error occurs
     * @throws java.sql.SQLTimeoutException  when the driver has determined that the
     * timeout value specified by the {@code setLoginTimeout} method
     * has been exceeded and has at least tried to cancel the
     * current database connection attempt
     */
    LazyProxyConnection getLazyConnection() throws SQLException;

}
